/**
 * DocumentInfoServiceImpl.java
 */
package com.prs.crm.service.document.knowledge.impl;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.prs.crm.context.Attach;
import com.prs.crm.context.Constrains;
import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.document.knowledge.DocDao;
import com.prs.crm.domain.doc.DocType;
import com.prs.crm.domain.document.knowledge.Doc;
import com.prs.crm.service.document.knowledge.DocService;
import com.prs.crm.service.impl.BaseServiceImpl;

/**
 * @author ZhuDongMei
 * @E-mail:1223984339@qq.com
 * @qq:1223984339
 * @version 创建时间：2011-3-16 上午11:12:28 简单说明
 */

public class DocServiceImpl extends BaseServiceImpl<Doc, DocDao> implements
		DocService {

	@Override
	public List<Doc> getAllDocs() {
		// TODO Auto-generated method stub
		return this.getDao().getAllDocs();
	}

	@Override
	public Collection<Doc> getRootDoc() {
		// TODO Auto-generated method stub
		return this.getDao().getRootDoc();
	}
	@Override
	public void saveDocumentInfos(Doc doc, File file, String fileFileName) {
        Attach cAttach=FileUtil.getInstance().saveFile(file, fileFileName,"",Constrains.UPLOAD_DIR_DOCUMENT);
		
		if(cAttach.getSrc()!=null){
			doc.setDocument_file(cAttach.getSrc());
		}
		this.getDao().save(doc);
		
	}

	@Override
	public Doc getDocById(Serializable id) {
		// TODO Auto-generated method stub
		return this.getDao().getDocById(id);
	}

	@Override
	public Collection<Doc> convertToDoc(String ids) {
		// TODO Auto-generated method stub
		try{
		Collection<Doc> docs = new ArrayList<Doc>();
		for(String id : ids.split(",")) {
			Doc doc = new Doc();
			doc.setId(Integer.valueOf(id));
			docs.add(doc);
		}
		return docs;
		}catch (NumberFormatException e) {
			e.printStackTrace();
			return null;
			}
	}

	/* (non-Javadoc)
	 * @see com.prs.crm.service.document.knowledge.DocService#removeDoc(java.lang.Integer)
	 */
	@Override
	public int removeDoc(Integer id) {
		// TODO Auto-generated method stub
		return this.getDao().removeDoc(id);
	}

}
